//
//  DWJVisitorViewController.swift
//  weibo
//
//  Created by 代伟佳 on 16/4/16.
//  Copyright © 2016年 代伟佳. All rights reserved.
//

import UIKit

class DWJVisitorViewController: UITableViewController {

    // 判断用户是否登录的标示
    var isLogin: Bool = DWJUersAccountTools.sharedTools.isLogin
    
    var visitorView: DWJVisitorView?
    
    override func loadView() {
        
        isLogin ? super.loadView() : setUpVisitorView()
        
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()

    }
    
    // MARK: - 监听事件 注册登录按钮
    @objc private func login() {

        let oauthVc = DWJOAuthViewController()
        
        presentViewController(UINavigationController(rootViewController: oauthVc), animated: true, completion: nil)

    }
    
    // MARK: - 设置导航栏
    private func setUpNav() {
    
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "login")
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: "login")
    }

    
    // MARK: - 设置视图
    private func setUpVisitorView() {
    
        visitorView = DWJVisitorView()
        
        setUpNav()
        
        visitorView?.visistorClosure = {
        
            self.login()
        }
        
        view = visitorView
        
    }
    

}
